package br.com.agiledev.webscrum.comuns;

import java.util.Comparator;

import br.com.agiledev.webscrum.entity.Item;

public class ItemComparator implements Comparator<Item> {

    private static ItemComparator instance;
    
    @Override
    public int compare(Item o1, Item o2) {

	long o1p = o1 != null ? o1.getPrioridade() : -1;
	long o2p = o2 != null ? o2.getPrioridade() : -1;
	
	if(o1p == o2p) {
	    String o1s = o1 != null ? o1.getNome() : "";
	    String o2s = o2 != null ? o2.getNome() : "";
	    
	    return o1s.compareTo(o2s);
	}
	
	return Long.valueOf(o1p).compareTo(Long.valueOf(o2p)) * -1;
    }
    
    public static ItemComparator getInstance() {
	
	if(instance == null) {
	    instance = new ItemComparator();
	}
	
	return instance;
    }

}
